package sort;

/**
 * 选择排序，每次把最小的放到前面
 * Created by JiaJia on 2019/8/13 0013.
 */
public class ChooseSort {
    public static void main(String[] args) {
        int[] nums={5,1,6,3,11,7,9,2,13};
        chooseSort(nums);
        for (int i = 0; i <nums.length ; i++) {
            System.out.println(nums[i]);
        }
    }
    private static void chooseSort(int[] nums){
        for (int i = 0; i <nums.length-1 ; i++) {
            for (int j = i+1; j < nums.length; j++) {
                if (nums[j]<nums[i]){
                    swap(nums,i,j);
                }
            }
        }
    }

    private static void swap(int[] nums,int i,int j){
        int tmp=nums[i];
        nums[i]=nums[j];
        nums[j]=tmp;
    }
}